﻿using KZ.Express.ENT;
using KZ.Express.Resource;
using KZ.Express.Task;
using KZ.Utilities;
using System;

namespace KZ.Express.Presenter
{
    public class OrderSurchargePresenter : PresenterBase
    {
        private new OrderTask _task;

        public OrderSurchargePresenter(IViewBase view)
            : base(view, new OrderENT())
        {
            _view = view;
            _task = new OrderTask();
        }

        /// <summary>
        /// Update surcharge order by carrier
        /// </summary>
        /// <returns></returns>
        public void UpdateSurcharge(int carrierID, DateTime from, DateTime to, decimal? orivat, decimal? vat,
            decimal? orifuel, decimal? fuel, decimal? rate)
        {
            try
            {
                _view.SetMessage(String.Empty, true);
                _task.UpdateSurcharge(carrierID, from, to, orivat, vat, orifuel, fuel, rate);
                _view.SetMessage(Message.BLM_SUC_UPDATE.ToString(), true);
            }
            catch (DataAccessException ex)
            {
                throw new BusinessLogicException(ex.Message);
            }
        }

        /// <summary>
        /// Update surcharge order by customer
        /// </summary>
        /// <returns></returns>
        public void UpdateSurcharge(int customerID, DateTime from, DateTime to, decimal? orivat, decimal? vat,
            decimal? orifuel, decimal? fuel, decimal? rate, decimal? cost, decimal? vndListOptional, string description)
        {
            try
            {
                _view.SetMessage(String.Empty, true);
                _task.UpdateSurcharge(customerID, from, to, orivat, vat, orifuel, fuel, rate, cost, vndListOptional, description);
                _view.SetMessage(Message.BLM_SUC_UPDATE.ToString(), true);
            }
            catch (DataAccessException ex)
            {
                throw new BusinessLogicException(ex.Message);
            }
        }
    }
}